<template>
  <div id="teml">
<!--分类-->
  <div id="cate">
    <ul id="cateul" v-bind="{style:'width:'+w+'px'}">
      <li @click="getPhoto(0)">全部</li>
      <li v-for="item in cate" @click="getPhoto(item.id)">{{item.title}}</li>
    </ul>
  </div>
  <!--图片列表-->
    <div class="photo" v-for="item in list" >
      <router-link v-bind="{to:'photoInfo/' + item.id}">
        <img v-lazy="item.img_url">
        <div class="dv">
          <h5 v-text="item.title"></h5>
          <p v-text="item.zhaiyao"></p>
        </div>
        </router-link>
    </div>
  </div>
</template>

<script>
import common from '../../kits/common.js';
import { Toast } from 'mint-ui';
export default {
  data(){
    return {
      cate:[],
      list:[],
      w:320
    }
  },
  methods:{
    getCate(){
      var url = common.apidomain + '/api/getimgcategory';
      var cateul = document.getElementById("cateul");
      this.$http.get(url).then(function(res){
        if(res.body.status != 0){
           Toast('aa');
           return;
        }
        this.cate = res.body.message;
        this.w = (res.body.message.length + 1 ) * 62;
        console.log(this.w)
      })
    },
    getPhoto(id){
      var url = common.newdomain + '/api/getimages/' + id;
      this.$http.get(url).then(function(res){
        if(res.body.status != 0){
           Toast('请求失败');
           return;
        }
        this.list = res.body.message;
        
      })
    }
  },
  created(){
    this.getCate();
    this.getPhoto(0);
  }
}
</script>

<style scoped>
	#cate{
    width:320px;
		max-width: 320px;
		overflow-x: auto;
	}
	#cate ul{
		padding-left: 10px;
	}
	#cate li{
		list-style: none;
		display: inline-block;
		color:#0094ff;
		font-size: 14px;
		padding-left: 6px;
	}
  .photo{
    position:relative;
  }
  .photo img{
    width: 100%;
    height:300px;
  }
  .photo .dv{
    position:absolute;
    left:0;
    bottom:5px;
    background-color: rgba(0,0,0,.3);
  }
  .photo .dv h5{
    color:#fff;
    font-weight:bold;
  }
  .photo .dv p{
    color:#fff;
  }
</style>